package com.appwoo.txtws.util;

import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.Toast;
import com.appwoo.txtws.bean.AutoSoftInfo;
import com.appwoo.txtws.component.Logger;

public class DragGrid extends GridView
{
  Animation AtoB;
  Animation BtoA;
  Animation DelDone;
  private int dragPosition;
  private int dropPosition;
  boolean flag = false;
  ViewGroup fromView;
  boolean isCountXY = false;
  private G_ItemChangeListener itemListener;
  private ImageView iv_drag;
  private Context mContext;
  private int mLastX;
  private int mLastY;
  int moveNum;
  private int numColumns;
  private G_PageListener pageListener;
  int stopCount = 0;
  private WindowManager windowManager;
  private WindowManager.LayoutParams windowParams;
  private int xtox;
  private int ytoy;

  public DragGrid(Context paramContext, int paramInt)
  {
    super(paramContext);
    this.numColumns = paramInt;
    this.mContext = paramContext;
  }

  public DragGrid(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    this.mContext = paramContext;
  }

  private void onDrag(int paramInt1, int paramInt2)
  {
    if (this.iv_drag != null)
    {
      this.windowParams.alpha = 0.8F;
      this.windowParams.x = (paramInt1 - this.mLastX - this.xtox + this.fromView.getLeft() - this.moveNum * Configure.screenWidth);
      this.windowParams.y = (paramInt2 - this.mLastY - this.ytoy + this.fromView.getTop() + (int)(40.0F * Configure.screenDensity));
      this.windowManager.updateViewLayout(this.iv_drag, this.windowParams);
    }
    if ((paramInt1 > -100 + Configure.screenWidth / 2) && (paramInt1 < 100 + Configure.screenWidth / 2) && (paramInt2 > -200 + Configure.screenHeight))
      this.pageListener.page(2, -100);
    label327: label594: 
    do
      while (true)
      {
        return;
        if (Configure.isDelDark)
          this.pageListener.page(3, -200);
        if (this.moveNum > 0)
        {
          if (((paramInt1 >= (1 + this.moveNum) * Configure.screenWidth - 20.0F * Configure.screenDensity) || (paramInt1 <= this.moveNum * Configure.screenWidth)) && (!Configure.isChangingPage));
          for (this.stopCount = (1 + this.stopCount); this.stopCount > 5; this.stopCount = 0)
          {
            this.stopCount = 0;
            if ((paramInt1 < (1 + this.moveNum) * Configure.screenWidth - 20.0F * Configure.screenDensity) || (Configure.curentPage >= -1 + Configure.countPages))
              break label327;
            Configure.isChangingPage = true;
            G_PageListener localG_PageListener4 = this.pageListener;
            int m = 1 + Configure.curentPage;
            Configure.curentPage = m;
            localG_PageListener4.page(0, m);
            this.moveNum = (1 + this.moveNum);
            return;
          }
          continue;
          if ((paramInt1 <= this.moveNum * Configure.screenWidth) && (Configure.curentPage > 0))
          {
            Configure.isChangingPage = true;
            G_PageListener localG_PageListener3 = this.pageListener;
            int k = -1 + Configure.curentPage;
            Configure.curentPage = k;
            localG_PageListener3.page(0, k);
            this.moveNum = (-1 + this.moveNum);
          }
        }
        else
        {
          Logger.i("draggrid", "x:" + paramInt1 + " movenum:" + this.moveNum + "  screenwidth:" + Configure.screenWidth + " d:" + Configure.screenDensity);
          if (((paramInt1 >= (1 + this.moveNum) * Configure.screenWidth - 20.0F * Configure.screenDensity) || (paramInt1 <= this.moveNum * Configure.screenWidth)) && (!Configure.isChangingPage));
          for (this.stopCount = (1 + this.stopCount); this.stopCount > 5; this.stopCount = 0)
          {
            this.stopCount = 0;
            if ((paramInt1 < (1 + this.moveNum) * Configure.screenWidth - 20.0F * Configure.screenDensity) || (Configure.curentPage >= -1 + Configure.countPages))
              break label594;
            Configure.isChangingPage = true;
            G_PageListener localG_PageListener2 = this.pageListener;
            int j = 1 + Configure.curentPage;
            Configure.curentPage = j;
            localG_PageListener2.page(0, j);
            this.moveNum = (1 + this.moveNum);
            return;
          }
        }
      }
    while ((paramInt1 > this.moveNum * Configure.screenWidth) || (Configure.curentPage <= 0));
    Configure.isChangingPage = true;
    G_PageListener localG_PageListener1 = this.pageListener;
    int i = -1 + Configure.curentPage;
    Configure.curentPage = i;
    localG_PageListener1.page(0, i);
    this.moveNum = (-1 + this.moveNum);
  }

  private void onDrop(int paramInt1, int paramInt2)
  {
    final DateAdapter localDateAdapter = (DateAdapter)getAdapter();
    AutoSoftInfo localAutoSoftInfo1 = (AutoSoftInfo)localDateAdapter.getItem(this.dragPosition);
    this.fromView.setDrawingCacheBackgroundColor(0);
    Configure.isMove = false;
    if (Configure.isDelDark)
    {
      this.DelDone = getDelAnimation(paramInt1, paramInt2);
      this.DelDone.setAnimationListener(new Animation.AnimationListener()
      {
        public void onAnimationEnd(Animation paramAnonymousAnimation)
        {
          Configure.removeItem = DragGrid.this.dragPosition;
          DragGrid.this.pageListener.page(5, -300);
        }

        public void onAnimationRepeat(Animation paramAnonymousAnimation)
        {
        }

        public void onAnimationStart(Animation paramAnonymousAnimation)
        {
        }
      });
      this.fromView.setVisibility(0);
      this.fromView.startAnimation(this.DelDone);
      return;
    }
    this.pageListener.page(4, -300);
    int i = pointToPosition(paramInt1 - this.moveNum * Configure.screenWidth, paramInt2);
    if (i != -1)
      this.dropPosition = i;
    if (this.moveNum != 0)
    {
      if ((Configure.curentPage == 0) && (i != -1))
      {
        if (i <= 11)
          break label180;
        i -= 8;
      }
      while (true)
      {
        this.itemListener.change(this.dragPosition, i, this.moveNum);
        this.moveNum = 0;
        return;
        label180: i = -1;
      }
    }
    if (((Configure.curentPage == 0) && (this.dropPosition <= 3)) || ((localAutoSoftInfo1.getAsParentid() > 0) && (localAutoSoftInfo1.getAsParentid() <= 8)))
      this.dropPosition = this.dragPosition;
    this.moveNum = 0;
    ViewGroup localViewGroup = (ViewGroup)getChildAt(this.dropPosition - getFirstVisiblePosition());
    int j = -(this.dropPosition % this.numColumns - this.dragPosition % this.numColumns);
    int k = -(this.dropPosition / this.numColumns - this.dragPosition / this.numColumns);
    this.AtoB = getDownAnimation(-j, -k);
    AutoSoftInfo localAutoSoftInfo2 = (AutoSoftInfo)localDateAdapter.getItem(this.dropPosition);
    PackageManager localPackageManager;
    if (this.dropPosition != this.dragPosition)
    {
      Logger.i("movexy", "drop:" + this.dropPosition + " drag:" + this.dragPosition + "   x-move:" + j + "    y-move:" + k);
      if ((localAutoSoftInfo2.getAsIsFolder() != 1) || (localAutoSoftInfo1.getAsIsFolder() != 0))
        break label526;
      localPackageManager = getContext().getPackageManager();
    }
    while (true)
    {
      try
      {
        ApplicationInfo localApplicationInfo = localPackageManager.getApplicationInfo(localAutoSoftInfo1.getAspkg(), 8192);
        localAutoSoftInfo2.add(new ShortcutInfo(localPackageManager.getActivityIcon(new ComponentName(localAutoSoftInfo1.getAspkg(), localAutoSoftInfo1.getActivityName())), localApplicationInfo.packageName, localAutoSoftInfo1.getActivityName()));
        ShowShortcutUtils.updateFolderIcon(getResources(), localAutoSoftInfo2);
        this.fromView.startAnimation(this.AtoB);
        this.AtoB.setAnimationListener(new Animation.AnimationListener()
        {
          public void onAnimationEnd(Animation paramAnonymousAnimation)
          {
            localDateAdapter.exchange(DragGrid.this.dragPosition, DragGrid.this.dropPosition);
            localDateAdapter.notifyDataSetChanged();
            com.appwoo.txtws.activity.MainActivity.isSoftMoving = 0;
          }

          public void onAnimationRepeat(Animation paramAnonymousAnimation)
          {
          }

          public void onAnimationStart(Animation paramAnonymousAnimation)
          {
          }
        });
        return;
      }
      catch (PackageManager.NameNotFoundException localNameNotFoundException)
      {
        localNameNotFoundException.printStackTrace();
        continue;
      }
      label526: if ((localAutoSoftInfo2.getAsIsFolder() == 0) && (localAutoSoftInfo1.getAsIsFolder() == 0) && (localAutoSoftInfo2.getAsParentid() == 0))
      {
        localDateAdapter.notifyDataSetChanged();
        com.appwoo.txtws.activity.MainActivity.isSoftMoving = 0;
        return;
      }
      if ((localAutoSoftInfo2.getAsIsFolder() == 1) && (localAutoSoftInfo1.getAsIsFolder() == 1))
        this.AtoB = getDownAnimation(0.0F, 0.0F);
      else
        localViewGroup.startAnimation(getMyAnimation(j, k));
    }
  }

  private void startDrag(final Bitmap paramBitmap, int paramInt1, int paramInt2)
  {
    this.windowManager = ((WindowManager)getContext().getSystemService("window"));
    Animation localAnimation = AnimationUtils.loadAnimation(getContext(), 2130968583);
    localAnimation.setAnimationListener(new Animation.AnimationListener()
    {
      public void onAnimationEnd(Animation paramAnonymousAnimation)
      {
        DragGrid.this.fromView.setVisibility(8);
        DragGrid.this.stopDrag();
        DragGrid.this.windowParams = new WindowManager.LayoutParams();
        DragGrid.this.windowParams.gravity = 51;
        DragGrid.this.windowParams.x = DragGrid.this.fromView.getLeft();
        DragGrid.this.windowParams.y = (DragGrid.this.fromView.getTop() + (int)(40.0F * Configure.screenDensity));
        DragGrid.this.windowParams.alpha = 0.8F;
        DragGrid.this.windowParams.height = -2;
        DragGrid.this.windowParams.width = -2;
        DragGrid.this.iv_drag = new ImageView(DragGrid.this.getContext());
        DragGrid.this.iv_drag.setImageBitmap(paramBitmap);
        DragGrid.this.windowManager.addView(DragGrid.this.iv_drag, DragGrid.this.windowParams);
        DragGrid.this.iv_drag.startAnimation(AnimationUtils.loadAnimation(DragGrid.this.getContext(), 2130968577));
      }

      public void onAnimationRepeat(Animation paramAnonymousAnimation)
      {
      }

      public void onAnimationStart(Animation paramAnonymousAnimation)
      {
      }
    });
    this.fromView.startAnimation(localAnimation);
    this.pageListener.page(1, -100);
  }

  private void stopDrag()
  {
    if (this.iv_drag != null)
    {
      this.windowManager.removeView(this.iv_drag);
      this.iv_drag = null;
      com.appwoo.txtws.activity.MainActivity.isSoftMoving = 0;
    }
  }

  public Animation getDelAnimation(int paramInt1, int paramInt2)
  {
    AnimationSet localAnimationSet = new AnimationSet(true);
    RotateAnimation localRotateAnimation = new RotateAnimation(0.0F, 360.0F, 1, 0.5F, 1, 0.5F);
    localRotateAnimation.setFillAfter(true);
    localRotateAnimation.setDuration(550L);
    AlphaAnimation localAlphaAnimation = new AlphaAnimation(1.0F, 0.0F);
    localAlphaAnimation.setFillAfter(true);
    localAlphaAnimation.setDuration(550L);
    localAnimationSet.addAnimation(localAlphaAnimation);
    localAnimationSet.addAnimation(localRotateAnimation);
    return localAnimationSet;
  }

  public Animation getDownAnimation(float paramFloat1, float paramFloat2)
  {
    AnimationSet localAnimationSet = new AnimationSet(true);
    TranslateAnimation localTranslateAnimation = new TranslateAnimation(1, paramFloat1, 1, paramFloat1, 1, paramFloat2, 1, paramFloat2);
    localTranslateAnimation.setFillAfter(true);
    localTranslateAnimation.setDuration(550L);
    AlphaAnimation localAlphaAnimation = new AlphaAnimation(0.1F, 1.0F);
    localAlphaAnimation.setFillAfter(true);
    localAlphaAnimation.setDuration(550L);
    ScaleAnimation localScaleAnimation = new ScaleAnimation(1.2F, 1.0F, 1.2F, 1.0F);
    localScaleAnimation.setFillAfter(true);
    localScaleAnimation.setDuration(550L);
    localAnimationSet.addAnimation(localTranslateAnimation);
    localAnimationSet.addAnimation(localAlphaAnimation);
    localAnimationSet.addAnimation(localScaleAnimation);
    return localAnimationSet;
  }

  public Animation getMyAnimation(float paramFloat1, float paramFloat2)
  {
    TranslateAnimation localTranslateAnimation = new TranslateAnimation(1, 0.0F, 1, paramFloat1, 1, 0.0F, 1, paramFloat2);
    localTranslateAnimation.setFillAfter(true);
    localTranslateAnimation.setDuration(550L);
    return localTranslateAnimation;
  }

  public boolean onInterceptTouchEvent(MotionEvent paramMotionEvent)
  {
    if (paramMotionEvent.getAction() == 0)
      return setOnItemLongClickListener(paramMotionEvent);
    return super.onInterceptTouchEvent(paramMotionEvent);
  }

  public boolean onTouchEvent(MotionEvent paramMotionEvent)
  {
    int i;
    int j;
    if ((this.iv_drag != null) && (this.dragPosition != -1))
    {
      i = (int)paramMotionEvent.getX();
      j = (int)paramMotionEvent.getY();
      switch (paramMotionEvent.getAction())
      {
      default:
      case 2:
      case 1:
      }
    }
    while (true)
    {
      return super.onTouchEvent(paramMotionEvent);
      if (!this.isCountXY)
      {
        this.xtox = (i - this.mLastX);
        this.ytoy = (j - this.mLastY);
        this.isCountXY = true;
      }
      Logger.i("draggrid", "x:" + i);
      onDrag(i, j);
      continue;
      stopDrag();
      onDrop(i, j);
      continue;
      com.appwoo.txtws.activity.MainActivity.isSoftMoving = 0;
    }
  }

  public void setLongFlag(boolean paramBoolean)
  {
    this.flag = paramBoolean;
  }

  public void setOnItemChangeListener(G_ItemChangeListener paramG_ItemChangeListener)
  {
    this.itemListener = paramG_ItemChangeListener;
  }

  public boolean setOnItemLongClickListener(final MotionEvent paramMotionEvent)
  {
    setOnItemLongClickListener(new AdapterView.OnItemLongClickListener()
    {
      public boolean onItemLongClick(AdapterView<?> paramAnonymousAdapterView, View paramAnonymousView, int paramAnonymousInt, long paramAnonymousLong)
      {
        try
        {
          DragGrid.this.isCountXY = false;
          AutoSoftInfo localAutoSoftInfo = (AutoSoftInfo)DragGrid.this.getItemAtPosition(paramAnonymousInt);
          if (localAutoSoftInfo.getAsname() == null);
          for (String str = "文件夹"; ; str = localAutoSoftInfo.getAsname())
          {
            Logger.i("draggrid", str);
            if ((localAutoSoftInfo.getAsParentid() == 0) || (localAutoSoftInfo.getAsParentid() == localAutoSoftInfo.getAsid()) || (localAutoSoftInfo.getAsParentid() <= 8))
              break;
            Toast.makeText(DragGrid.this.mContext, DragGrid.this.mContext.getResources().getString(2131428233), 0).show();
            return true;
          }
          if (((paramAnonymousInt > 7) || (Configure.curentPage != 0)) && ((paramAnonymousInt > 2) || (Configure.curentPage != 1)))
          {
            com.appwoo.txtws.activity.MainActivity.isSoftMoving = 1;
            Configure.isMove = true;
            int i = (int)paramMotionEvent.getX();
            int j = (int)paramMotionEvent.getY();
            DragGrid.this.mLastX = i;
            DragGrid.this.mLastY = j;
            DragGrid localDragGrid = DragGrid.this;
            DragGrid.this.dropPosition = paramAnonymousInt;
            localDragGrid.dragPosition = paramAnonymousInt;
            if (DragGrid.this.dragPosition == -1)
              return true;
            DragGrid.this.fromView = ((ViewGroup)DragGrid.this.getChildAt(DragGrid.this.dragPosition - DragGrid.this.getFirstVisiblePosition()));
            DragGrid.this.fromView.destroyDrawingCache();
            DragGrid.this.fromView.setDrawingCacheEnabled(true);
            DragGrid.this.fromView.setDrawingCacheBackgroundColor(-9586707);
            Bitmap localBitmap1 = Bitmap.createBitmap(DragGrid.this.fromView.getDrawingCache());
            Bitmap localBitmap2 = Bitmap.createBitmap(localBitmap1, 0, 0, localBitmap1.getWidth(), localBitmap1.getHeight());
            DragGrid.this.startDrag(localBitmap2, i, j);
          }
          return true;
        }
        catch (Exception localException)
        {
          while (true)
            localException.printStackTrace();
        }
      }
    });
    return super.onInterceptTouchEvent(paramMotionEvent);
  }

  public void setPageListener(G_PageListener paramG_PageListener)
  {
    this.pageListener = paramG_PageListener;
  }

  public static abstract interface G_ItemChangeListener
  {
    public abstract void change(int paramInt1, int paramInt2, int paramInt3);
  }

  public static abstract interface G_PageListener
  {
    public abstract void page(int paramInt1, int paramInt2);
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.util.DragGrid
 * JD-Core Version:    0.6.2
 */